package com.mapforge.gui.frames.map;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JFrame;

import com.mapforge.collection.WeakReferenceInstanceProvider;
import com.mapforge.listener.RenderListener;
import com.mapforge.listener.TileMapCreationEvent;
import com.mapforge.listener.TileMapCreationListener;
import com.mapforge.map.TileMap;

public class ResizeMapDialogProvider extends
		WeakReferenceInstanceProvider<ResizeMapDialog> implements
		TileMapCreationListener, ActionListener {
	private TileMap tileMap;
	private JFrame parent;
	private List<RenderListener> renderListeners;

	public ResizeMapDialogProvider(JFrame parent) {
		this.parent = parent;
		this.renderListeners = new ArrayList<RenderListener>();
	}

	public boolean addRenderListener(RenderListener listener) {
		return this.renderListeners.add(listener);
	}

	public void clearRenderListeners() {
		this.renderListeners.clear();
	}

	public boolean removeRenderListener(RenderListener listener) {
		return this.renderListeners.remove(listener);
	}

	@Override
	protected ResizeMapDialog createNewInstance() {
		return new ResizeMapDialog(parent, tileMap,renderListeners);
	}

	@Override
	public void tileMapCreationPerformed(TileMapCreationEvent mapCreationEvent) {
		this.tileMap = mapCreationEvent.getTileMapCreated();
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		this.getInstance().setVisible(true);
	}
}
